package demo;

import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

public class RightMenu extends JFrame{

	private JPopupMenu menu = new JPopupMenu();
	public RightMenu(){
		init();
	}

	private void init() {
		setBounds(new Rectangle(500,400));
		setTitle("Menu Test");
		setDefaultCloseOperation(this.EXIT_ON_CLOSE);
		setLocationRelativeTo(null);
		//menu.setVisible(true);
		rightMouse();
		add(menu);
	}

	private void rightMouse() {
		JMenuItem mAll, mCopy, mCut,mPaste,mDelete;
		menu.add(new JMenuItem("全选"));
		menu.add(new JMenuItem("复制"));
		menu.add(new JMenuItem("剪切"));
		menu.add(new JMenuItem("粘贴"));
		menu.add(new JMenuItem("删除"));
		this.addMouseListener(new MouseAdapter(){
			public void mouseClicked(MouseEvent e){
				if(e.getButton() == MouseEvent.BUTTON3){
					menu.show(RightMenu.this,e.getX(),e.getY());
				}
			}
		});
	}
}
